package com.cade.agriculturemall.model;

import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVObject;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lobby on 2017/11/22.
 */
@AVClassName("ClassifyGoodsThird")
public class GoodsDetailEntity extends AVObject {
    private String title;
    private String site;
    private String priceOld;
    private String priceNew;
    private String quantitate;
    private List<String> picture;
    private String parentId;
    private List<Integer> treatment;
    private Integer sellOff;  //销量
    private Integer surplus;    //库存

    public List<Integer> getTreatment() {
        JSONArray array = getJSONArray("treatment");
        if (array != null) {
            treatment = new Gson().fromJson(array.toString(), new TypeToken<List<Integer>>() {
            }.getType());
        } else {
            treatment = new ArrayList<>();
        }
        return treatment;
    }

    public void setTreatment(List<Integer> treatment) {
        put("treatment", treatment);
    }

    public String getParentId() {
        return getString("parentId");
    }

    public void setParentId(String parentId) {
        put("parentId", parentId);
    }


    public String getTitle() {
        return getString("category_name");
    }

    public void setTitle(String title) {
        put("category_name", title);
    }


    public String getPriceOld() {
        return getString("price_old");
    }

    public void setPriceOld(String priceOld) {
        put("price_old", priceOld);
    }

    public String getPriceNew() {
        return getString("price_new");
    }

    public void setPriceNew(String priceNew) {
        put("price_new", priceNew);
    }

    public String getQuantitate() {
        return getString("quantitate");
    }

    public void setQuantitate(String quantitate) {
        put("quantitate", quantitate);
    }

    public List<String> getPicture() {
        JSONArray array = getJSONArray("picture");
        if (array != null) {
            picture = new Gson().fromJson(array.toString(), new TypeToken<List<String>>() {
            }.getType());
        } else {
            picture = new ArrayList<>();
        }
        return picture;
    }

    public void setPicture(List<String> picture) {
        put("picture", picture);
    }

    public String getSite() {
        return getString("site");
    }

    public void setSite(String site) {
        put("site", site);
    }

    public String getSellOff() {
        return getString("sell_offs");
    }

    public void setSellOff(String sellOff) {
        put("sell_offs", sellOff);
    }

    public Integer getSurplus() {
        return getInt("surplus");
    }

    public void setSurplus(Integer surplus) {
        put("surplus", surplus);
    }
    public String getShoper() {
        return getString("shop_name");
    }
    public void setShoper(String shoper) {
        put("shop_name", shoper);
    }
}
